﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Niagara.Sample.Data;
using System.Data.Services.Client;

namespace Niagara.Sample
{
  public partial class MainPage : UserControl
  {
    GamesEntities ctx = new GamesEntities(new Uri("/GameService.svc", UriKind.RelativeOrAbsolute));

    public MainPage()
    {
      InitializeComponent();

      var qry = (from g in ctx.Games
                 where g.Genre.Name == "Shooter"
                 orderby g.ReleaseDate descending
                 select g) as DataServiceQuery<Game>;

      qry.BeginExecute(new AsyncCallback(r =>
        {
          try
          {
            theDataForm.ItemsSource = DataServiceCollection.CreateTracked<Game>(ctx, qry.EndExecute(r));
          }
          catch (Exception ex)
          {
            MessageBox.Show(ex.ToString());
          }
        }), null);
    }
  }
}
